<!doctype html>
<html>
<head>
    <title>内容添加</title>
    <?php $this->load->module('admin/index/page_header');?>
    <script type="text/javascript">
        window.UEDITOR_HOME_URL = "<?php echo URLPRE.'static/public/Lib/ueditor/';?>";
    </script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/ueditor/ueditor.config.js" charset="utf-8"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/ueditor/ueditor.all.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/ueditor/lang/zh-cn/zh-cn.js" charset="utf-8"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/color/color.js"></script>

    <!--引入CSS-->
    <link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/public/Lib/webuploader/webuploader.css">
    <!--引入JS-->
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/webuploader/webuploader.js"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/admin/js/common.js?newversion"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/select2/select2.min.js"></script>
    <script type="text/javascript" src="<?php echo URLPRE;?>static/public/Lib/select2/select2_locale_zh-CN.js"></script>
    <link href="<?php echo URLPRE;?>static/public/Lib/select2/select2.css" rel="stylesheet" />
    <link href="<?php echo URLPRE;?>static/public/Lib/select2/select2-bootstrap.css" rel="stylesheet" />
</head>
<body>
<div class="wrap">
    <div id="home_toptip"></div>
    <div class="nav">
        <ul>
            <li><a href="<?php echo site_url('weixin/vote/index');?>">投票活动列表</a></li>

            <?php if(empty($data)){?>

                <li class="current"><a href="<?php echo site_url('weixin/vote/add');?>">添加投票活动</a></li>
            <?php }else{?>
                <li class="current"><a >编辑投票活动</a></li>
            <?php }?>
        </ul>
    </div>
    <div class="table_full">
        <form class="formvalidate" action="" method="post">
            <div class="h_a">添加投票活动</div>
            <div class="table_full">
                <table class="tab_label" width="100%" id="general_config">
                    <col class="th" /></col>
                    <tbody>
                    <tr>
                        <th>投票活动标题</th>
                        <td>
                            <input type="text" name="Form[title]" value="<?php echo empty($data) ? '' : $data['title'];?>" class="input rounded" size="80" validate="{required:true,rangelength:[1,80]}" />
                        </td>
                    </tr>


                    <tr>
                        <th>活动图片</th>

                        <td class="rowform">
                            <ul>
                                <li><input type="text" class="input rounded" style="width: 300px;" name="Form[pic]" id="file_url" validate="{required:true}" value="<?php echo $data['pic'];?>"/></li>
                                <li><div id="filePicker">选择图片</div></li>
                                <?php if($data['pic']):?>
                                    <li><div class="webuploader-pick view_pic" data-uri="<?php echo URLPIC.$data['pic'];?>" title="查看图片">查看图片</div></li>
                                <?php endif;?>
                            </ul>

                        </td>
                    </tr>

                    <tr>
                        <th>活动介绍</th>
                        <td>
                            <script style="width:100%;" id="editor" name="Form[desc]" type="text/plain"><?php echo empty($data['desc']) ? '' : $data['desc'];?></script>
                        </td>
                    </tr>

                    <tr>
                        <th>团型</th>
                        <td>
                            <textarea cols="50" rows="6" style="width:200px!important;" validate="{required:true}"  name="Form[tuanxing]"><?php echo empty($data) ? '亲子游
蜜月游
父母游
海岛游
其他' : $data['tuanxing'];?></textarea>
                            <span class="fun_tips">格式：一行一个</span>
                        </td>
                    </tr>

                    </tbody>
                </table>
            </div>
            <div class="btn_wrap">
                <div class="btn_wrap_pd">
                    <input type="hidden" name="id" value="<?php echo !empty($data) ? $data['id'] : 0?>" />
                    <button type="submit" class="btn btn_submit J_ajax_submit_btn">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    //文本编辑器
    UE.getEditor('editor', {toolbars:[['fullscreen', 'source', '|', 'undo', 'redo', '|',
        'bold', 'italic', 'underline', 'strikethrough', '|',
        'superscript', 'subscript','|', 'forecolor', 'backcolor','|',
        'removeformat','insertorderedlist', 'insertunorderedlist', 'selectall','cleardoc','|',
        'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','|',
        'link', 'unlink','emotion','insertimage']
    ], initialFrameHeight:200});
    $(function(){
        //$('.supplier').select2({placeholder: "请选择",allowClear: true});
        //setTimeout(function(){
        //  $('.dist').select2({placeholder: "请选择",allowClear: true});
        //}, 300);


        $("#scenic_sel").select2({
            placeholder: "选择关联景区",
            minimumInputLength: 1,
            ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
                url: "<?php echo site_url('order/adminticket/select_scenic')?>",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        q: term, // search term
                    };
                },
                results: function (data) { // parse the results into the format expected by Select2.
                    // since we are using custom formatting functions we do not need to alter remote JSON data
                    return {results: data};
                }
            },
            initSelection: function(element, callback) {
                var id = $(element).val();
                callback({name:'<?php echo $data['scenic_name']?>'});
            },
            formatResult: movieFormatResult, // omitted for brevity, see the source of this page
            formatSelection: movieFormatSelection,  // omitted for brevity, see the source of this page
            dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
            escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
        });
    });
    //添加售价
    $('#add_group').click(function(){
        var $this = $(this);
        var data_uri = $this.attr('data-uri');
        ddate = ddisplay_price = dprice = dspecial = dth_price = '';
        $.dialog.load(data_uri,{
            id:'group_price',
            title:'添加价格',
            padding:'',
            resize: false,
            drag: true,
            width:'700px',
            zIndex:'100',
            fixed: true,
            ok: function () {
                var date = $('#Kalendae').val();
                var disprice = parseFloat($('#seat_num').val()).toFixed(2);
                var thprice = parseFloat($('#th_price').val()).toFixed(2);
                var group_num = parseFloat($('#group_num').val()).toFixed(2);
                var special = parseFloat($('#special').val()).toFixed(2);
                if(isNaN(disprice) || disprice<=0){
                    alert('请填入正确的票面价');
                    return false;
                }
                if(isNaN(thprice) || thprice<=0){
                    alert('请填入正确的同行价');
                    return false;
                }
                if(isNaN(group_num) || group_num<=0){
                    alert('请填入正确的网上价');
                    return false;
                }
                if(isNaN(special) || special<0){
                    special=0;
                }
                if(parseFloat(disprice)<parseFloat(group_num)){
                    alert('网上价不能大于票面价');
                    return false;
                }

                var df = ((disprice-group_num)+0.0000001)+'';
                var h = '<li style="margin-top:5px;">' +
                    '<input type="hidden" class="ddate" name="p[date][]" value="'+date+'" />' +
                    '<input type="hidden" name="p[display_price][]" value="'+disprice+'" />' +
                    '<input type="hidden" name="p[th_price][]" value="'+thprice+'" />' +
                    '<input type="hidden" name="p[price][]" value="'+group_num+'" />' +
                    '<input type="hidden" name="p[special][]" value="'+special+'" />' +
                    '<a href="javascript:;" class="del" onclick="$(this).parent().remove()"></a>' +
                    '<strong>票面价:</strong><a>'+disprice+'</a>元， ' +
                    '<strong>同行价:</strong><a>'+thprice+'</a>元， ' +
                    '<strong>网上价:</strong><a>'+group_num+'</a>元， '+
                    '<strong>优惠:</strong><a>'  +(special?special : (df.substr(0, df.indexOf('.')+3))) + '</a>元， '+
                    '<strong>日期:</strong><a>'  +date+'</a>'+
                    '</li>';
                $(h).insertBefore($this.parent());
            }
        });
    });
    //编辑价格
    var ddate,ddisplay_price,dth_price,dth_price,dprice,dspecial;  //编辑价格传参
    function edit_group(obj){
        var $this = $(obj);
        var data_uri = $this.attr('data-uri');
        ddate = $this.parent().find('.ddate').val();
        ddisplay_price = $this.parent().find('.ddisplay_price').val();
        dth_price = $this.parent().find('.dth_price').val();
        dprice = $this.parent().find('.dprice').val();
        dspecial = $this.parent().find('.dspecial').val();

        $.dialog.load(data_uri,{
            id:'group_price',
            title:'编辑价格',
            padding:'',
            resize: false,
            drag: true,
            width:'700px',
            zIndex:'100',
            fixed: true,
            ok: function () {
                var date = $('#Kalendae').val();
                var disprice = $('#seat_num').val();
                var group_num = $('#group_num').val();
                var special = $('#special').val();
                var thprice = $('#th_price').val();
                if(parseFloat(disprice)<parseFloat(group_num)){
                    alert('网上价不能大于票面价');
                    return false;
                }
                var h =
                    '<input type="hidden" class="ddate" name="p[date][]" value="'+date+'" />' +
                    '<input type="hidden" class="ddisplay_price" name="p[display_price][]" value="'+disprice+'" />' +
                    '<input type="hidden" class="dth_price" name="p[th_price][]" value="'+thprice+'" />' +
                    '<input type="hidden" class="dprice" name="p[price][]" value="'+group_num+'" />' +
                    '<input type="hidden" class="dspecial" name="p[special][]" value="'+special+'" />' +
                    '<a href="javascript:;" class="edit_group" onclick="edit_group(this)" data-uri="<?php echo site_url('ticket/admin/ticket_group');?>">编辑</a> ' +
                    '<a href="javascript:;" class="del" onclick="$(this).parent().remove()"></a>' +
                    '<strong>票面价:</strong><a>'+disprice+'</a>元， ' +
                    '<strong>同行价:</strong><a>'+thprice+'</a>元， ' +
                    '<strong>网上价:</strong><a>'+group_num+'</a>元， '+
                    '<strong>优惠:</strong><a>'  +(special?special : (disprice-group_num)) + '</a>元， '+
                    '<strong>日期:</strong><a>'  +date+'</a>';
                $this.parent().html(h);
            }
        });
    }

    var sc = 1 ;
    function add_scenic(obj){
        var h = '<li style="margin-top:5px"><select id="supplier_'+sc+'" style="width:300px;"  name="t[scenic][]"><option></option><?php foreach ($scenic as $v) { ?><option value="<?php echo $v['id'];?>"><?php echo str_replace("'"," ",$v['name']) ;?></option><?php }?></select><a href="javascript:;" class="del" onclick="$(this).parent().remove()"></a></li>';
        $(h).insertBefore($(obj).parent());
        $('#supplier_'+sc).select2({placeholder: "请选择",allowClear: true});
        sc++;
    }
    /**
     * 组装下拉列表显示信息
     * @param movie
     * @returns {string}
     */
    function movieFormatResult(movie) {
        var markup = "<table class='movie-result'><tr>";
        markup += "<td class='movie-info'><div class='movie-title'>" + movie.name + "</div>";
        markup += "</td></tr></table>";
        return markup;
    }

    /**
     * 返回值
     * @param movie
     * @returns {*}
     */
    function movieFormatSelection(movie) {
        var uri = $('#use_date').attr('data-uri'), goods_id=movie.id,goods_type=$('#goods_type').select2("val");
        var $html = '<option value="0">全部</option>';
        //不存在ID时 不执行
        if(movie.id!=undefined) {
            // alert(movie.id);return false;
            $('#scenic_sel').val(movie.id);
        }

        //产品名称
        if(movie.name!=undefined){
            // $('#scenic_sel').val(movie.name);
        }

        return movie.name;
    }
    //图片上传
    upload_image("<?php echo site_url('admin/upload/ajax_upload');?>",'filePicker','file_url');
</script>
</body>
</html>